//
//  WeDetailBottomView.m
//  WeGalaxy
//
//  Created by Zheng on 2017/6/27.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "WeDetailBottomView.h"

@interface WeDetailBottomView ()

@property (nonatomic, strong) UIButton *msgBtn; //留言
@property (nonatomic, strong) UIButton *upBtn; //点赞
@property (nonatomic, strong) UIButton *priceBtn; //出价
@property (nonatomic, strong) UIButton *chatBtn; //聊一聊

@end

@implementation WeDetailBottomView

#pragma mark - 点击事件
- (void)buttonClickAction:(UIButton *)sender {
    _clickActionBlock([self getStyleWithTag:sender.tag]);
}

- (WeDetailBottomViewClickStyle)getStyleWithTag:(NSInteger)tag {
    
    WeDetailBottomViewClickStyle style = WeDetailBottomViewClickStyleLeaveMessage;
    
    switch (tag-10000) {
        case 0:
            style = WeDetailBottomViewClickStyleLeaveMessage;
            break;
        case 1:
            style = WeDetailBottomViewClickStyleThumbUp;
            break;
        case 2:
            style = WeDetailBottomViewClickStylePrice;
            break;
        case 3:
            style = WeDetailBottomViewClickStyleChat;
            break;
    }
    return style;
}

#pragma mark - 初始化
- (instancetype)init {
    self = [super init];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        [self subviewsInView];
    }
    return self;
}

#pragma mark - 子视图
- (void)subviewsInView {
    [self addSubview:self.msgBtn];
    [self addSubview:self.upBtn];
    [self addSubview:self.priceBtn];
    [self addSubview:self.chatBtn];
}

- (UIButton *)msgBtn {
    if (!_msgBtn) {
        _msgBtn = [self getClickButton:(CGRect){20,0,49,49} withTag:10000];
    }
    return _msgBtn;
}

- (UIButton *)upBtn {
    if (!_upBtn) {
        _upBtn = [self getClickButton:(CGRect){85,0,49,49} withTag:10001];
    }
    return _upBtn;
}

- (UIButton *)chatBtn {
    if (!_chatBtn) {
        _chatBtn = [self getClickButton:(CGRect){kSCREEN_WIDTH-100,0,100,49} withTag:10002];
    }
    return _chatBtn;
}

- (UIButton *)priceBtn {
    if (!_priceBtn) {
        _priceBtn = [self getClickButton:(CGRect){kSCREEN_WIDTH-220,0,120,49} withTag:10003];
    }
    return _priceBtn;
}

- (UIButton *)getClickButton:(CGRect)frame withTag:(NSInteger)tag {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = frame;
    btn.tag = tag;
    [btn addTarget:self action:@selector(buttonClickAction:) forControlEvents:UIControlEventTouchUpInside];
    btn.backgroundColor = kRGB_COLOR(arc4random()%255, arc4random()%255, arc4random()%255, 1);
    return btn;
}


@end
